package com.hpf.lease.web.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hpf.lease.common.result.Result;
import com.hpf.lease.model.bean.ApartmentInfo;
import com.hpf.lease.web.admin.dto.ApartmentSearchSubmitDto;
import com.hpf.lease.web.admin.dto.ApartmentSubmitDto;
import com.hpf.lease.web.admin.service.ApartmentInfoService;
import com.hpf.lease.web.admin.vo.ApartmentInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/admin/apartment")
@Tag(name = "公寓管理模块")
public class ApartmentController {
    @Resource
    ApartmentInfoService apartmentInfoService;
    @PostMapping("/updateReleaseStatusById")
    @Operation(summary = "根据id更改房间发布状态")
    public Result<Object> updateReleaseStatusById(@RequestParam Long id,@RequestParam String status){
        return Result.build(apartmentInfoService.updateReleaseStatusById(id,status));
    }
    @PostMapping("/saveOrUpdate")
    @Operation(summary = "更新或新增公寓的信息")
    public Result<Object> saveOrUpdate(@RequestBody ApartmentSubmitDto submitDto){
        return Result.build(apartmentInfoService.saveOrUpdateInfo(submitDto));
    }
    @GetMapping("/pageItem")
    @Operation(summary = "根据分页条件查询公寓列表")
    public Result<Page<ApartmentInfoVo>> getPageItem(ApartmentSearchSubmitDto submitDto){
        return Result.ok(apartmentInfoService.getPageItem(submitDto));
    }
    @GetMapping("/listInfoByDistrictId")
    @Operation(summary = "根据区县id查询公寓信息列表")
    public Result<ApartmentInfo> listInfoByDistrictId(@RequestParam long id){
        return Result.ok(apartmentInfoService.getOne(Wrappers.lambdaQuery(ApartmentInfo.class)
                .eq(ApartmentInfo::getDistrictId , id)));
    }
    @GetMapping("/getDetailById")
    @Operation(summary = "根据ID获取公寓详细信息")
    public Result<ApartmentInfo> getDetailById(@RequestParam long id){
        return Result.ok(apartmentInfoService.getById(id));
    }
    @DeleteMapping("/removeById")
    @Operation(summary = "根据id删除公寓信息")
    public Result<ApartmentInfo> removeById(@RequestParam long id){
        return Result.build(apartmentInfoService.removeById(id));
    }
}
